package com.tianshuo.construct.main;

import com.tianshuo.construct.ConstructConfig;
import com.tianshuo.construct.model.Animal;
import com.tianshuo.construct.model.Cat;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;

/**
 * 只是使用BeanFactory通过注册bd，实例化bean
 */
public class BeanFactoryApplicationContext {
    public static void main(String[] args) {

        // Spring内部也是使用的DefaultListableBeanFactory
        DefaultListableBeanFactory listableBeanFactory = new DefaultListableBeanFactory();

        BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition("animal").getBeanDefinition();
        beanDefinition.setBeanClassName("com.tianshuo.construct.model.Animal");

        listableBeanFactory.registerBeanDefinition("animal",beanDefinition);

        // getBean从bdm中获取bd，然后实例化
        Animal animal = listableBeanFactory.getBean(Animal.class);

        System.out.println(animal);


    }
}
